﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using Infragistics.Controls.Grids;
using ibba.src.noriskbo.Models;
using ibba.src.noriskbo;

namespace ibba.src.noriskbo.code.converter
{

    public class DeleteButtonPortfolioClienteConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            UnboundColumnDataContext p = value as UnboundColumnDataContext;

            if (p == null || p.RowData == null)
                return Visibility.Collapsed;
            else
            {
                PortfolioClienteGrid portfolioClienteGrid = p.RowData as PortfolioClienteGrid;

                if (portfolioClienteGrid == null || portfolioClienteGrid.StatusImportacao == null || (portfolioClienteGrid.IdCliente == 0 && portfolioClienteGrid.IdVeiculoLegal == 0))
                    return Visibility.Collapsed;
            }

            return Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


    public class DeleteButtonPortfolioConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            UnboundColumnDataContext p = value as UnboundColumnDataContext;

            if (p == null || p.RowData == null)
                return Visibility.Collapsed;
            else
            {
                PortfolioGrid portfolioGrid = p.RowData as PortfolioGrid;

                if (portfolioGrid == null || portfolioGrid.StatusImportacao == null || (portfolioGrid.IdISDA == null && (portfolioGrid.CdContrato == null || portfolioGrid.CdContrato == String.Empty)))
                    return Visibility.Collapsed;
            }

            return Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class StatusPortImportToImageConverter : IValueConverter
    {

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is string)
                switch (value.ToString().Trim())
                {
                    case Constantes.StatusPortfolioImportLote.ALTERACAO:
                        return Constantes.SourceImageApp.STATUS_PORT_IMPORT_A;

                    case Constantes.StatusPortfolioImportLote.ALTERACAO_AVISO:
                        return Constantes.SourceImageApp.STATUS_PORT_IMPORT_A_ALERT;

                    case Constantes.StatusPortfolioImportLote.ALTERACAO_ERRO:
                        return Constantes.SourceImageApp.STATUS_PORT_IMPORT_A_ERROR;

                    case Constantes.StatusPortfolioImportLote.INCLUSAO:
                        return Constantes.SourceImageApp.STATUS_PORT_IMPORT_I;

                    case Constantes.StatusPortfolioImportLote.INCLUSAO_AVISO:
                        return Constantes.SourceImageApp.STATUS_PORT_IMPORT_I_ALERT;

                    case Constantes.StatusPortfolioImportLote.INCLUSAO_ERRO:
                        return Constantes.SourceImageApp.STATUS_PORT_IMPORT_I_ERROR;

                    case Constantes.StatusPortfolioImportLote.EXCLUSAO:
                        return Constantes.SourceImageApp.STATUS_PORT_IMPORT_E;

                    case Constantes.StatusPortfolioImportLote.GRAVADO:
                        return Constantes.SourceImageApp.STATUS_PORT_IMPORT_G;
                        
                    default:
                        return null;
                }
            else
                return null;

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //throw new NotImplementedException();
            return value;
        }

        #endregion

    }

    public class TextToUpperConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is string)
                return value.ToString().ToUpper();
            else
                return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
